package org.breathe.dynamic.thread.pool.core.spring;

import cn.hutool.core.util.StrUtil;
import lombok.extern.slf4j.Slf4j;
import org.breathe.thread.pool.common.entity.BreatheDtpProperties;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.ansi.AnsiColor;
import org.springframework.boot.ansi.AnsiOutput;

/**
 * 图标生成
 * @author: breathe
 * @createTime: 2025-04-11
 */
@Slf4j
public class BreatheDTPBannerPrinter implements InitializingBean {

    private final BreatheDtpProperties breatheDtpProperties;
    public BreatheDTPBannerPrinter(BreatheDtpProperties breatheDtpProperties, String version) {
        this.breatheDtpProperties = breatheDtpProperties;
        this.version = version != null ? version : "";
    }
    private static final String NAME = " :: Breathe Dynamic Thread Pool :: ";
    private static final String BANNER = """
              
              ____                 _   _          _____ _______ _____ \s
             |  _ \\               | | | |        |  __ \\__   __|  __ \\\s
             | |_) |_ __ ___  __ _| |_| |__   ___| |  | | | |  | |__) |
             |  _ <| '__/ _ \\/ _` | __| '_ \\ / _ \\ |  | | | |  |  ___/\s
             | |_) | | |  __/ (_| | |_| | | |  __/ |__| | | |  | |    \s
             |____/|_|  \\___|\\__,_|\\__|_| |_|\\___|_____/  |_|  |_|    \s
                                                                      \s
                                                                          \s
            """;
    private final String version;
    private static final int STRAP_LINE_SIZE = 50;
    /**
     * 打印banner
     */
    private void printBanner() {
        String bannerVersion = StrUtil.isNotEmpty(version) ? " (v" + version + ")" : "no version.";
        StringBuilder padding = new StringBuilder();
        while (padding.length() < STRAP_LINE_SIZE - (bannerVersion.length() + NAME.length())) {
            padding.append(" ");
        }
        log.info(AnsiOutput.toString(BANNER, "\n", AnsiColor.RED, NAME, AnsiColor.GREEN, padding.toString(), bannerVersion, "\n\n"));
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        printBanner();
    }
}
